{include file="public/header"}
<title>需求列表</title>
</head>

<body>

<div class="page-container">
    <!--<a style="text-decoration:none" class="btn btn-primary add "  href="javascript:;" title="新增"><span class="label label-primary">新增</span></a>-->
    <div class="mt-20">
        <div class="title-border">
            <div class="flex1">名称</div>
            <div class="flex1">部门</div>
            <div class="flex1">最后时间</div>
            <div class="flex1">状态</div>
            <div class="flex1">操作</div>
        </div>
        {volist name='data' id='vo'}
        <div class="content-border">
            <div class="flex1">{$vo.username}</div>
            <div class="flex1" style="color: red"><?php if(empty($vo['store_id'])){ ?>后勤<?php }else{?>店长<?php }?></div>
            <div class="flex1" style="color: red"><?php if(empty($vo['last_login_time'])){ ?><?php }else{?>{:date('Y-m-d H:i:s',$vo.last_login_time)}<?php }?></div>
            <div class="flex1"><?php if($vo['status']==0){ ?><span style="color: green">正常</span><?php }elseif($vo['status']==1){?><span style="color: red">禁用</span><?php }?></div>
            <div class="flex1">
                <a class="ch-button ch-wathet edit" data-id="{$vo.admin_id}" href="javascript:;" title="编辑">编辑</a>
                <a class="ch-button ch-blue reset" data-id="{$vo.admin_id}" href="javascript:;" title="重置密码">重置密码</a>
                <?php if($vo['status']==0){ ?>
                <a class="ch-button ch-red del" data-id="{$vo.admin_id}" data-state="1" href="javascript:;" title="禁用">禁用</a>
                <?php }elseif($vo['status']==1){?>
                <a class="ch-button ch-red del" data-id="{$vo.admin_id}"  data-state="0" href="javascript:;" title="启用">启用</a>
                <?php }?></div>
            </div>

        {/volist}
        </div>


    <div class="pages" style="float: right">{$data->render()}</div>

    </div>


    {include file="public/footer"}
    <script type="text/javascript">

        /**
         * 接单提醒
         */
        $('.add').click(function () {

            var src = "{:Url('index/role/add')}";
            layer.open({
                type: 2,
                area: ['1000px', '600px'],
                fix: false,
                maxmin: true,
                shade: 0.4,
                title: '添加管理员',
                content: src
            });
        });
        /**
         * 重置密码
         */
        $('.reset').click(function () {
            var id = $(this).attr('data-id');
            var obj = {};
            obj.admin_id = id;
            var src = "{:Url('index/role/reset')}";
            layer.confirm('确认要重置该用户的密码吗？', function (index) {
                $.ajax({
                    type: 'POST',
                    url: src,
                    dataType: 'json',
                    data: obj,
                    success: function (data) {
                        var res = JSON.parse(data);
                        console.log(res);
                        if (res.code == 200) {
                            layer.msg(res.msg, {icon: 1, time: 2000});
                        } else {
                            layer.msg(res.msg, {icon: 5, time: 1000});
                        }

                    },
                    error: function (data) {
                        console.log(data.msg);
                    },
                });
            });
        });
        /**
         * 删除
         */
        $('.del').click(function () {
            var id = $(this).attr('data-id');
            var state = $(this).attr('data-state');
            var msg = '';
            var obj = {};
            obj.label_id = id;
            obj.state = state;
            var src = "{:Url('index/role/del')}";
            if( obj.state==0){
                msg='确认要启用吗？';
            }else {
                msg='确认要禁用吗？';
            }
            layer.confirm(msg, function (index) {
                $.ajax({
                    type: 'POST',
                    url: src,
                    dataType: 'json',
                    data: obj,
                    success: function (data) {
                        var res = JSON.parse(data);
                        if (res.code == 200) {
                            layer.msg(res.msg, {icon: 1, time: 2000}, function () {
                                setTimeout("window.location.reload()", 1);
                            });
                        } else {
                            layer.msg(res.msg, {icon: 5, time: 1000});
                        }

                    },
                    error: function (data) {
                        console.log(data.msg);
                    },
                });
            });
        });
        $('.page-container').on('click','.edit',function () {
            var winWidth = $(window).width();
            var areaWidth = "";
            var areaHeight = "";
            if( winWidth > 768 ){
                areaWidth = "769px"
                areaHeight = "600px"
            } else {
                areaWidth = '100%'
                areaHeight = '100%'
            }

            var id = $(this).attr('data-id');
            var src = "{:Url('index/role/edit')}";
            layer.open({
                type: 2,
                area: [areaWidth, areaHeight],
                fix: false,
                maxmin: true,
                shade: 0.4,
                title: '编辑管理员',
                content: src + '?admin_id=' + id

            });

        });

    </script>
</body>
</html>